/*!
 * @file consulta.js
 * @project MB Consultoria Jurídica
 * @developer Thiago Braga <thibraga06@gmail.com>
 * @designer Ana Lau <contato@analau.com.br>
 * @url www.mbconsultoriajuridica.com.br
 */


var input = $('.list input'),
  salvar = $('[id*="salvar"]');


/**
 * @function saveForm
 * @description Save the form via ajax.
 */
var saveForm = (function (button) {
  var data = { grupo: button.attr('id').replace("salvar-", "") };
  $.post(base_url('grupos/ajax_save'), data, function (response) {
    noty({ text: response.message, type: response.type });
  }, 'json');
});


input.iCheck({
  checkboxClass: 'icheckbox_flat-grey',
  handle: 'checkbox'
});


/* Events */
salvar.on('click', function () {
  var $this = $(this);
  saveForm($this);
});